package priv.mill.server;

import java.util.Arrays;

import org.eclipse.jetty.util.UrlEncoded;
import org.junit.Test;

public class TestCode {

	@Test
	public void testUrlDecode() {

		String code = "if(arr[in]&lt;arr[in-1]){";
		String decode = UrlEncoded.decodeString(code);
		System.out.println(decode);

	}

	public static void main(String[] args) {
		long[] arr = new long[100];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = (long) (Math.random() * 1000);
		}
		System.out.println(Arrays.toString(arr));
		sort(arr);
		System.out.println(Arrays.toString(arr));
		int index = erfenChazhao(arr, arr[10]);
		System.out.println(index);

	}

	@Test
	public void testMaopao(long[] arr) throws Exception {
//		for(int i=0;i<arr.length-1;i++){//外层循环控制排序趟数
//			for(int j=0;j<arr.length-1-i;j++){//内层循环控制每一趟排序多少次
//			if(arr[j]>arr[j+1]){
//				long temp=arr[j];
//				arr[j]=arr[j+1];
//				arr[j+1]=temp;
//		　　　　　}
//		　　　}
//		} 
	}

	private static int erfenChazhao(long[] arr, long l) {
		int low = 0;
		int height = arr.length - 1;
		while (true) {
			int mid = (low + height) / 2;
			if (arr[mid] == l)
				return mid;
			else if (low > height)
				return -1;
			else {
				if (arr[mid] > l) {
					height = mid - 1;
				} else {
					low = mid + 1;
				}
			}
		}
	}

	private static void sort(long[] arr) {

		int out, in;
		for (out = arr.length; out > 0; out--) {
			for (in = 1; in < out; in++) {
				if (arr[in] < arr[in - 1]) {
					long temp = arr[in];
					arr[in] = arr[in - 1];
					arr[in - 1] = temp;
				}
			}
		}
	}
}
